package cn.yinuo.website.common.util;

import cn.yinuo.website.common.bean.BaseQueryVo;
import cn.yinuo.website.user.entity.User;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;

import java.util.Map;

public class PageQueryUtils {
    public static <T> Wrapper<T> getWrapper(BaseQueryVo<T> queryVo) {
        Wrapper wrapper =  new EntityWrapper<>().allEq(queryVo.getAndCondition());

        queryVo.getLikeCondition().entrySet().stream().forEach(one -> {wrapper.like(one.getKey(),one.getValue().toString());});
        queryVo.getGtCondition().entrySet().stream().forEach(one -> {wrapper.gt(one.getKey(),one.getValue().toString());});
        queryVo.getLtCondition().entrySet().stream().forEach(one -> {wrapper.lt(one.getKey(),one.getValue().toString());});
        queryVo.getOrderByCondition().entrySet().stream().forEach(one -> {wrapper.orderBy(one.getKey(),one.getValue().toString().toLowerCase().equals("asc"));});
        return wrapper;
    }
}
